package com.css.fxfzaqbz.modules.supergraph.controller;

import com.css.fxfzaqbz.base.response.RestResponse;
import com.css.fxfzaqbz.modules.base.entity.District;
import com.css.fxfzaqbz.modules.callJcData.service.GasholderService;
import com.css.fxfzaqbz.modules.supergraph.entity.CqgDataEntity;
import com.css.fxfzaqbz.modules.supergraph.service.SupergraphService;
import com.css.fxfzaqbz.modules.supergraph.vo.*;
import com.css.fxfzaqbz.util.RestTemplateUtil;
import com.css.fxfzaqbz.zcpt.sys.service.SUserService;
import com.css.fxfzaqbz.zcpt.sys.service.SysRoleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.slw.common.helper.PropsHelper;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.*;

/**
 * @author y1fan
 * @create 2023-02-03 16:03
 */
@RestController
@RequestMapping("/fxfzaqbz/data")
@Slf4j
public class SupergraphController {

    @Resource
    private SupergraphService supergraphService;

    @Resource
    private RestTemplateUtil restTemplateUtil;


    @Resource
    private SUserService sUserService;
    @Resource
    private SysRoleService sysRoleService;

    Properties configGroup = PropsHelper.loadProps("slw-config.properties");
    //获取分布图版本的URL
    String lxUrl = configGroup.getProperty("restTemplateUrl") + "/fxfzsjxt/datacenter/sysDataVersion/page";
    String versionUrl = configGroup.getProperty("restTemplateUrl") + "/datacenter/house/getDataVersion";

    @Resource
    private GasholderService gasholderService;

    /*
     * 调用超图接口  辅助分析五张图
     * */
    @PostMapping("/supergraph")
    public RestResponse Supergraph(@RequestBody SupergraphVO supergraphVO) throws InterruptedException {
        return supergraphService.Supergraph(supergraphVO);
    }

    /*
    * 危险源避让分布图
    * */
    @PostMapping("/sourceOfDangerBr")
    public RestResponse sourceOfDangerBr(@RequestBody SourceOfDangerBrVO sourceOfDangerBrVO) throws InterruptedException {
        return supergraphService.sourceOfDangerBr(sourceOfDangerBrVO);
    }

    /*
     * 地址灾害隐患点分布图
     * */
    @PostMapping("/hazardPoint")
    public RestResponse hazardPoint(@RequestBody SourceOfDangerBrVO sourceOfDangerBrVO) throws InterruptedException {
        return supergraphService.hazardPoint(sourceOfDangerBrVO);
    }

    /*
     * 危险源分布图
     * */
    @PostMapping("/sourceOfDanger")
    public RestResponse sourceOfDanger(@RequestBody SourceOfDangerBrVO sourceOfDangerBrVO) throws InterruptedException {
        return supergraphService.sourceOfDanger(sourceOfDangerBrVO);
    }

    /*
     * 断层分布图
     * */
    @PostMapping("/faultage")
    public RestResponse faultage(@RequestBody SourceOfDangerBrVO sourceOfDangerBrVO) throws InterruptedException {
        return supergraphService.faultage(sourceOfDangerBrVO);
    }

    /*
     * 地震构造分布图
     * */
    @PostMapping("/seismotectonics")
    public RestResponse seismotectonics(@RequestBody SourceOfDangerBrVO sourceOfDangerBrVO) throws InterruptedException {
        return supergraphService.seismotectonics(sourceOfDangerBrVO);
    }


    /*
     * 历史地震分布图
     * */
    @PostMapping("/historicalEarthquake")
    public RestResponse historicalEarthquake(@RequestBody SourceOfDangerBrVO sourceOfDangerBrVO) throws InterruptedException {
        return supergraphService.historicalEarthquake(sourceOfDangerBrVO);
    }


    /*
     * 人口分布图
     * */
    @PostMapping("/populationDistribution")
    public RestResponse populationDistribution(@RequestBody SourceOfDangerBrVO sourceOfDangerBrVO) throws InterruptedException {
        return supergraphService.populationDistribution(sourceOfDangerBrVO);
    }



    /*
     * 人口伤亡及紧急安置
     * */
    @PostMapping("/HumanCasualtiesAndPlacement")
    public RestResponse HumanCasualtiesAndPlacement(@RequestBody HumanCasualtiesVO humanCasualtiesVO) throws InterruptedException {
        return supergraphService.HumanCasualtiesAndPlacement(humanCasualtiesVO);
    }


    /*
     * 查询储气罐版本信息
     * */
    @PostMapping("/getCqgDataVersion")
    public RestResponse getCqgDataVersion(@RequestBody CqgDataEntity cqgDataEntity) {
        return RestResponse.succeed(gasholderService.getCqgDataVersion(cqgDataEntity));
    }

    /*
     * 一键出图页面查看接口
     * */
    @GetMapping("/getSupergraph")
    public RestResponse getSupergraph() {
        return RestResponse.succeed(supergraphService.getSupergraph());
    }

    /*
     * 一键出图页面版本查看接口
     * */
    @GetMapping("/getDataVersion/{num}")
    public String getDataVersion(@PathVariable("num") String num) {
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("typeCode",num);
        ResponseEntity<String> stringResponseEntity = restTemplateUtil.sendHttpRequest1(lxUrl, paramMap);
        return stringResponseEntity.getBody();

    }

    /*
     * 一键出图页面版本查看接口   //根据省市区
     * */
    @PostMapping("/getDataVersionBySSQ")
    public String getDataVersionBySSQ(@RequestBody VersionVO versionVO) {
        String num = versionVO.getNum();
        List<District> list = versionVO.getList();
        List<String> pList=new ArrayList<>();
        List<String> cList=new ArrayList<>();
        List<String> xList=new ArrayList<>();
        for (District district : list) {
            if (StringUtils.isNotBlank(district.getProvinceId())){
                pList.add(district.getProvinceId());
            }
            if (StringUtils.isNotBlank(district.getCityId())){
                cList.add(district.getCityId());
            }
            if (StringUtils.isNotBlank(district.getPrefectureId())){
                xList.add(district.getPrefectureId());
            }
        }

        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("num",num);
        paramMap.put("aaa",pList);
       // paramMap.put("bbb",cList);
       // paramMap.put("ccc",xList);
        paramMap.put("page",versionVO.getPage());
        paramMap.put("rows",versionVO.getRows());
        ResponseEntity<String> stringResponseEntity = restTemplateUtil.sendPostHttpRequest1(versionUrl, paramMap);
        return stringResponseEntity.getBody();

    }

    /*
     * 重点场所风险评估一键出图生成应急疏散辅助决策图
     * */
    @PostMapping("/assessEmphasisNetworkPath")
    public RestResponse assessEmphasisNetworkPath(@RequestBody AssessEmphasisVo assessEmphasisVo) throws InterruptedException {
        return supergraphService.assessEmphasisNetworkPath(assessEmphasisVo);
    }









}
